package com.drug.wms.service.impl;

import com.drug.common.core.domain.model.LoginUser;
import com.drug.common.enums.BusinessSeqEnum;
import com.drug.common.utils.SecurityUtils;
import com.drug.wms.domain.BusGoodsBaseInfo;
import com.drug.wms.domain.BusGoodsPrice;
import com.drug.wms.domain.BusPriceConf;
import com.drug.wms.mapper.BusGoodsBaseInfoMapper;
import com.drug.wms.mapper.BusPriceConfMapper;
import com.drug.wms.service.GenerateSequence;
import com.drug.wms.service.IBusPriceConfService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


/**
 * 价格配置Service业务层处理
 *
 * @author ruoyi
 * @date 2021-11-08
 */
@Service
public class BusPriceConfServiceImpl implements IBusPriceConfService {
    @Autowired
    private BusPriceConfMapper busPriceConfMapper;
    @Autowired
    private BusGoodsBaseInfoMapper busGoodsBaseInfoMapper;

    /**
     * 查询价格配置
     *
     * @param id 价格配置主键
     * @return 价格配置
     */
    @Override
    public BusPriceConf selectBusPriceConfById(String id) {
        return busPriceConfMapper.selectBusPriceConfById(id);
    }

    /**
     * 查询价格配置列表
     *
     * @param busPriceConf 价格配置
     * @return 价格配置
     */
    @Override
    public List<BusPriceConf> selectBusPriceConfList(BusPriceConf busPriceConf) {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        busPriceConf.setDeptId(loginUser.getDeptId());
        return busPriceConfMapper.selectBusPriceConfList(busPriceConf);
    }

    /**
     * 新增价格配置
     *
     * @param busPriceConf 价格配置
     * @return 结果
     */
    @Override
    public int insertBusPriceConf(BusPriceConf busPriceConf) {
        busPriceConf.setPriceNo(GenerateSequence.genSeqNo(BusinessSeqEnum.JG.getCode()));
        return busPriceConfMapper.insertBusPriceConf(busPriceConf);
    }

    /**
     * 修改价格配置
     *
     * @param busPriceConf 价格配置
     * @return 结果
     */
    @Override
    public int updateBusPriceConf(BusPriceConf busPriceConf) {
        return busPriceConfMapper.updateBusPriceConf(busPriceConf);
    }

    /**
     * 批量删除价格配置
     *
     * @param ids 需要删除的价格配置主键
     * @return 结果
     */
    @Override
    public int deleteBusPriceConfByIds(String[] ids) {
        return busPriceConfMapper.deleteBusPriceConfByIds(ids);
    }

    /**
     * 删除价格配置信息
     *
     * @param id 价格配置主键
     * @return 结果
     */
    @Override
    public int deleteBusPriceConfById(String id) {
        return busPriceConfMapper.deleteBusPriceConfById(id);
    }


    @Override
    public List<BusGoodsPrice> selectBusGoodsPriceListByGoodsNo(String goodsNo) {
        List<BusGoodsPrice> busGoodsPrices = busPriceConfMapper.selectBusGoodsPriceListByGoodsNo(goodsNo);
        BusGoodsBaseInfo busGoodsBaseInfo = busGoodsBaseInfoMapper.selectBusGoodsBaseInfoByGoodsNo(goodsNo);
        //组装价格下拉框
        busGoodsPrices.add(new BusGoodsPrice(busGoodsBaseInfo.getNationalWholesalePrice(), "国批价"));
        busGoodsPrices.add(new BusGoodsPrice(busGoodsBaseInfo.getNationalRetailPrice(), "国零价"));
        busGoodsPrices.add(new BusGoodsPrice(busGoodsBaseInfo.getTransferPrice(), "调货价"));
        return busGoodsPrices;
    }
}
